package de.stefanocke.roo.wicket.form;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.springframework.roo.classpath.itd.ItdTypeDetailsProvidingMetadataItem;

import de.stefanocke.roo.wicket.RooForm;
import de.stefanocke.roo.wicket.Stereotypes;
import de.stefanocke.roo.wicket.base.ModelClassAwareItdMetadataProviderBase;
import de.stefanocke.roo.wicket.base.ModelClassAwareMetadataCreationParams;
import de.stefanocke.roo.wicket.form.formfields.FormFieldsMetadata;

@Component
@Service
public class FormMetadataProvider extends ModelClassAwareItdMetadataProviderBase<FormMetadata, FormAnnotationValues> {

	public FormMetadataProvider() {
		super(RooForm.class, FormMetadata.class, FormAnnotationValues.class);
	}

	@Override
	protected ItdTypeDetailsProvidingMetadataItem getMetadataInternal(
			ModelClassAwareMetadataCreationParams<FormAnnotationValues> cmcp) {

		FormFieldsMetadata ffm = findWicketMetadata(cmcp.getMid(), cmcp.getModelClass(), FormFieldsMetadata.class);
		return new FormMetadata(cmcp, ffm);
	}

	@Override
	protected String[] requiredStereotypes() {
		return new String[] {Stereotypes.FORM, Stereotypes.FORM_FIELDS, Stereotypes.IENTITYBINDINGS};
	}

}
